/**
 * 
 */
package com.thor.palmmall.rest.inspect.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.OperateInfoToBeanConverter;
import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.SAttachment2Converter;
import com.thor.palmmall.rest.inspect.AInspectBill;
import com.thor.palmmall.spi.common.SOperateInfoConverter;
import com.thor.palmmall.spi.inspect.SInspectBill;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SInspectBill4SaveConverter implements Converter<AInspectBill, SInspectBill> {

  public static SInspectBill4SaveConverter getInstance() {
    if (instance == null)
      instance = new SInspectBill4SaveConverter();
    return instance;
  }

  private static SInspectBill4SaveConverter instance;

  private SInspectBill4SaveConverter() {
  }

  @Override
  public SInspectBill convert(AInspectBill source) {
    if (source == null) {
      return null;
    }
    SInspectBill target = new SInspectBill();

    target.setBeginTime(source.getBeginTime());
    target.setBillNumber(source.getBillNumber());
    target.setBizState(source.getBizState());
    target.setBpmInstance(source.getBpmInstance());
    target.setBpmMessage(source.getBpmMessage());
    target.setBpmState(source.getBpmState());
    target.setBuilding(UCN.newInstance(source.getBuilding()));

    target.setCategory(source.getCategory());
    target.setCategoryItem(source.getCategoryItem());
    target.setConfirmInfo(source.getConfirmInfo());
    target.setCreateInfo(SOperateInfoConverter.getInstance()
        .convert(OperateInfoToBeanConverter.getInstance().convert(source.getCreateInfo())));

    target.setDealInfo(source.getDealInfo());
    target.setDutyPerson(UCN.newInstance(source.getDutyPerson()));

    target.setEndTime(source.getEndTime());
    target.setExpectTime(source.getExpectTime());

    target.setFloor(UCN.newInstance(source.getFloor()));
    target.setInspector(UCN.newInstance(source.getInspector()));
    target.setInspectTime(source.getInspectTime());
    target.setInspectTopic(source.getInspectTopic());
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setPlace(source.getPlace());
    target.setRemark(source.getRemark());
    target.setStore(source.getStore());
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());

    target.setLastModifyInfo(SOperateInfoConverter.getInstance()
        .convert(OperateInfoToBeanConverter.getInstance().convert(source.getLastModifyInfo())));

    target.setAfterPictures(
        ConverterUtil.convert(source.getAfterPictures(), SAttachment2Converter.getInstance()));
    target.setBeforePictures(
        ConverterUtil.convert(source.getBeforePictures(), SAttachment2Converter.getInstance()));
    
    target.setAbortMsg(source.getAbortMsg());
    return target;
  }

}
